<?php

namespace App\Models\MainDB;

use Illuminate\Database\Eloquent\Model;

class GameSugarJoin extends Model
{
    protected $connection = 'mysql';

    protected $table = 'ln_game_sugar_join';

    public $timestamps = false;

    public function getJoinGameUserByManyGameId(array $gameIdArr)
    {
        return $this->selectRaw("count(1) as num,game_id")
            ->whereIn('game_id', $gameIdArr)
            ->groupBy('game_id')
            ->get()
            ->toArray();
    }

    public function getJoinUserDetail($condition)
    {
        $field = "j.user_id,0 as get_num,0 as result,ud.nickname";
        return $this->from($this->table . ' as j')
            ->selectRaw($field)
            ->where($condition)
            ->leftJoin('ln_user_data as ud', 'j.user_id', '=', 'ud.user_id')
            ->get()->toArray();
    }
}
